import axios from "axios";

const request = axios.create({
  timeout: 10000,
  // baseURL:"/api"
});

request.interceptors.request.use((config) => {
  const token = sessionStorage.getItem("token");
  const headers = {};
  if (token) {
    headers.authorization = token;
  }
  return {
    ...config,
    headers,
  };
});
request.interceptors.response.use(
  (response) => {
    return response.data;
  },
  (err) => {
    switch (err.response.status) {
      case 401:
          alert('无权限')
        break;
      case 403:
        break;
      case 404:
        break;
      case 500:
        break;
      default:
        break;
    }
  }
);

export default request;